<template>

  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>资源管理</el-breadcrumb-item>
      <el-breadcrumb-item>资源列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>

      <el-form :inline="true" :model="queryinfo" class="demo-form-inline" size="mini">
        <el-form-item label="资源名字">
          <el-input v-model="queryinfo.title" placeholder="资源名字" clearable/>
        </el-form-item>
        <el-form-item label="资源类型">
          <el-select v-model="queryinfo.calss" placeholder="资源类型" clearable filterable>
            <el-option label="Zone one" value="shanghai"></el-option>
            <el-option label="Zone two" value="beijing"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="资源状态">
          <el-select v-model="queryinfo.statu" placeholder="资源状态" clearable filterable>
            <el-option label="下线" value="-1"></el-option>
            <el-option label="上线" value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="GetData()">Query</el-button>
        </el-form-item>
      </el-form>

      <hr>
      <el-table :data="tableData" style="width: 100%; ">
        <el-table-column prop="title" label="资源名称" width="180"/>
        <el-table-column prop="info" label="资源说明" width="180"/>
        <el-table-column prop="calss" label="资源类型" width="180"/>
        <el-table-column prop="site" label="资源地址" width="180"/>
        <el-table-column prop="link" label="跳转链接" width="180"/>
        <el-table-column prop="sort" label="排序" width="180"/>
        <el-table-column prop="statu" label="状态" width="180"/>
        <el-table-column label="#操作" width="180"/>
      </el-table>
      <br>

      <!--      <el-pagination-->
      <!--          v-model:currentPage="queryinfo.page"-->
      <!--          :page-sizes="[3,100, 200, 300, 400]"-->
      <!--          :page-size="queryinfo.size"-->
      <!--          layout="sizes, prev, pager, next"-->
      <!--          :total="total"-->
      <!--          @size-change="handleSizeChange"-->
      <!--          @current-change="handleCurrentChange"-->
      <!--      />-->


      <!--总数超过一页，再展示分页器-->
      <el-pagination
          background
          layout="prev, pager, next"
          :total="total"
          :page-size="queryinfo.size"
          :current-page="queryinfo.page"
          @current-change="changePage"
      />

    </el-card>
  </div>
</template>

<script>
import {onMounted, reactive, toRefs} from 'vue'
import axios from '@/utils/axios'

export default {
  name: 'Good',
  setup() {
    const state = reactive({
      queryinfo: {
        page:1,
        size:10
      },
      currentPage: 1, // 当前页
      pageSize: 10, // 分页大小
      total: 10000,
      tableData: []
    })
    onMounted(() => {
      GetData()
    })
    // 获取轮播图列表
    const GetData = async () => {
      const {data: res} = await axios.get('resources', {params: state.queryinfo})
      if (res.code !== 1000) return this.$message.error(res.msg)
      state.tableData = res.data.list
      state.total = res.data.total
    }
    const changePage = (val) => {
      console.log(11)
      state.queryinfo.page = val
      GetData()
    }
    return {
      ...toRefs(state),
      GetData,
      changePage
    }
  }
}

</script>

<style scoped>

</style>
